//////////////////////////////////////////////////////////////////////////////////////////////////////////// // // //---------------------------- Ebrahim Foulaadvand- Somayyeh Belbasi, 13 Oct 2006 ----------------- // // // // The routine "Advection" solves the 1D wave equation using forward time centered space // // scheme and forward time backward space methods. Periodic boundary condition is used. // The system length L and the wave velocity c are set to one. Initial wave shape is // cosine-modulated Gaussian pulse. // // // // // // // //////////////////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include #include #include #include using namespace std; main() { double tau=0.004,h,L=1,c=1,sigma=0.05,lambda=0.2,k=2*M_PI/lambda,x; int N=200,i,n,T=1000; ofstream file0 ("initial profile n=0.plt"); //output file for the profile at timestep n=0. ofstream file1 ("profile FTCS n=20.plt"); //output file for the profile at timestep n=100. ofstream file2 ("profile FTCS n=80.plt"); //output file for the profile at timestep n=500. ofstream file3 ("profile FTBS n=20.plt"); //output file for the profile at timestep n=100. ofstream file4 ("profile FTBS n=80.plt"); //output file for the profile at timestep n=500. ofstream file5 ("profile FTBS n=100.plt"); //output file for the profile at timestep n=500. vector u(N+1,0),unew(N+1,0),uB(N+1,0),uBnew(N+1,0); // Arrays "u" and "unew" store the current and updated values // of the scaler function u(x,t) at grid points. "B" stands for backward space. h=L/N; cout<<"h= "<